package com.netease.xone.itemview;

import protocol.meta.AppImage;
import protocol.meta.AppInfo;
import protocol.meta.AppInfoDetail;
import Utils.StackTraceUtil;
import android.content.Context;
import android.text.TextUtils;
import android.view.View;
import android.view.View.OnClickListener;

import com.netease.log.NTLog;
import com.netease.xone.R;
import com.netease.xone.view.PopupImagePreview;
import com.netease.xone.widget.LoadingImageView;


public class RenderDetailImage implements IRenderInfoBase, OnClickListener{
    private static final String TAG = RenderDetailImage.class.getSimpleName();
    
    private int mWidth;
    private View mRoot;
    private LoadingImageView mImage;

    public RenderDetailImage(View v) {
        mRoot = v;
        mWidth = v.getContext().getResources().getDisplayMetrics().widthPixels;
        mImage = (LoadingImageView)v.findViewById(R.id.image1);
        mImage.setOnClickListener(this);
    }

    @Override
    public void renderView(Context context, AppInfo appInfo) {
        
    }

    @Override
    public void renderView(Context context, AppInfoDetail appInfoDetail) {
        
    }
    
    public void renderView(Context context, AppImage appImage) {
        NTLog.d(TAG, StackTraceUtil.getMethodName());
        
        if (null != appImage && !TextUtils.isEmpty(appImage.getUrl())) {
            mRoot.setVisibility(View.VISIBLE);
        } else {
            mRoot.setVisibility(View.GONE);
            return;
        }
       
        String url = null;
        url = appImage.getUrl();
        mImage.setServerClipSize(mWidth, 0);
        mImage.setLoadingImage(url);
        mImage.setTag(appImage);
    }
    
    @Override
    public void onClick(View v) {
        NTLog.d(TAG, StackTraceUtil.getMethodName());
        
        PopupImagePreview.luach(v.getContext(), (AppImage)v.getTag());
    }
   
}
